<template>
  <view class="detail-container">
    <view class="detail-header">
      <text class="detail-title">{{noticeInfo.noticeTitle}}</text>
      <view class="detail-meta">
        <text class="time">{{noticeInfo.createTime}}</text>
      </view>
    </view>
    
    <view class="detail-content">
      <text class="content-text">{{noticeInfo.noticeContent}}</text>
    </view>
  </view>
</template>

<script>
import config from '@/config/config.js'

export default {
  data() {
    return {
      noticeInfo: {}
    }
  },
  methods: {
    async getNoticeDetail(noticeId) {
      try {
        uni.showLoading({
          title: '加载中...'
        })
        
        const result = await this.$http.post(config.api.slconfig.noticeDetail, {
          noticeId: noticeId
        })
        
        console.log('公告详情响应:', result)
        
        if (result.data.code === 200 || result.data.code === 201) {
          this.noticeInfo = result.data.data || {}
        } else {
          throw new Error(result.data.msg || '获取公告详情失败')
        }
      } catch (err) {
        console.error('获取公告详情失败:', err)
        uni.showToast({
          title: err.message || '获取公告详情失败',
          icon: 'none'
        })
      } finally {
        uni.hideLoading()
      }
    }
  },
  onLoad(options) {
    if (options.noticeId) {
      this.getNoticeDetail(options.noticeId)
    } else {
      uni.showToast({
        title: '参数错误',
        icon: 'none'
      })
    }
  }
}
</script>

<style>
.detail-container {
  padding: 30rpx;
  background-color: #fff;
  min-height: 100vh;
}

.detail-header {
  margin-bottom: 40rpx;
}

.detail-title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  line-height: 1.4;
  margin-bottom: 20rpx;
  display: block;
}

.detail-meta {
  display: flex;
  align-items: center;
  margin-top: 20rpx;
}

.time {
  font-size: 24rpx;
  color: #999;
}

.detail-content {
  padding-top: 20rpx;
  border-top: 1rpx solid #eee;
}

.content-text {
  font-size: 28rpx;
  color: #333;
  line-height: 1.8;
  text-align: justify;
}
</style> 